<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>已生产计划表</title>

    <link href="//unpkg.com/layui@2.8.10/dist/css/layui.css" rel="stylesheet">
    <script src="static/js/jquery-3.6.0.js"></script>
    <script src="//unpkg.com/layui@2.8.10/dist/layui.js"></script>
    <style>
        .layui-btn-primary-custom {
            background-color: blue;
            color: white;
        }
    </style>
</head>
<body>
<div id="div_subb" style="display: none">
    <form class="layui-form" action="#" method="POST" id="fm">
        <div class="layui-form-item">
            <label class="layui-form-label">产量</label>
            <div class="layui-input-block">
                <input type="text" id="producedCount" name="producedCount" lay-verify="required" placeholder="请输入产量" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>
<table class="layui-table" id="subTableContainer" lay-filter="subTableContainer"></table>
<!-- 引入 layui.js -->
<script>
    layui.use('table', function () {
        var table = layui.table;
        // 渲染表格
        table.render({
            elem: '#subTableContainer',
            url: 'tailor/querySubPlan', // 数据接口，替换成您的后端接口地址
             page: true ,//开启分页
             height: 300 ,
            limits:7,
            cols: [[ // 表头
                {field: 'productionPlanId', title: '生产编号', width: 150},
                {field: 'quotationNumber', title: '订单编号', width: 150},
                {field: 'styleNumber', title: '款号', width: 150},
                {field: 'productName', title: '商品名称', width: 80},
                {field: 'scheduleTime', title: '生产日期', width: 150},
                {field: 'staffDepartment', title: '生产部门', width: 150},
                {field: 'schedeleCount', title: '计划生产数量', width: 150},
                {field: 'producedCount', title: '已生产数量', width: 150},
                {fixed: '', title: '操作', toolbar: '#barDemo', width: 160},
                {fixed: 'id', title: 'id',hide:true,width:30 }
            ]],
            done: function (res, curr, count) {
                // 表格渲染完成后的回调函数
            }
        });
        // 监听工具条
        table.on('tool(subTableContainer)', function(obj){
            var data = obj.data; // 当前行数据
            var productionPlanId = data.id;
            var layEvent = obj.event; // 点击的事件名
            if(obj.event === 'deleteSubmission'){
                // 删除操作
                layer.confirm('确认删除该数据吗？', function(index){
                    $.ajax({
                        type: 'get',
                        url: 'tailor/delsubmission', // 替换成您的后端删除接口地址
                        data: {id: data.id}, // 替换成实际的参数
                        success: function(res){
                            layer.msg(res.message)

                        },
                        error: function(){
                            alert("删不了啊")
                        }
                    });
                    layer.close(index);
                    var table = layui.table;
                    table.reload("subTableContainer");
                });
            } else if(obj.event === 'updateSubmission'){
                    // 调用删除数据的接口，替换成您的后端接口地址
                    layer.open({
                        type: 1,
                        title: '更改当前日期的产量?',
                        content: $("#div_subb"),
                        area: ['500px', '500px'], // 弹窗大小
                        btn: ['修改产量', '取消'],
                        yes: function (index, layero) {
                        var producedCount = $("[name=producedCount]").val();
                            $.ajax({
                                type: 'post',
                                url: 'tailor/upsubmission', // 替换成您的后端修改接口地址
                                data: {id:data.id,producedCount:producedCount}, // 替换成实际的参数
                                success: function(res){
                                    layer.msg(res.message)

                                },
                                error: function(){
                                  alert("产品数量不符合要求")
                                }
                            });
                            layer.close(index); // 关闭弹窗
                            var table = layui.table;
                            table.reload("subTableContainer");
                            // 刷新表格

                        }
                    });
            }
        });
    });
</script>
</body>
<script type="text/html" id="barDemo">
    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="deleteSubmission">删除</button>
    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="updateSubmission">修改</button>
</script>
</html>